Skip to content

feat: add --timeout flag to override the startup readiness deadline#358

Merged
gtsiolis merged 3 commits into
mainfrom
pro-357-lstk-start-should-time-out-on-failed-startup-0511
Jul 23, 2026
Merged

feat: add --timeout flag to override the startup readiness deadline#358
gtsiolis merged 3 commits into
mainfrom
pro-357-lstk-start-should-time-out-on-failed-startup-0511

Conversation

@gtsiolis

@gtsiolis gtsiolis commented Jul 2, 2026

Copy link
Copy Markdown
Member

Motivation

lstk start could wait indefinitely when the emulator never became healthy, hanging CI and other non-interactive jobs until an external timeout killed them (reported by harsh.mishra). The startup wait itself was later bounded in #390 (per-mode defaults + LSTK_STARTUP_TIMEOUT); this PR adds the command-line --timeout flag PRO-357 asked for, so the deadline is controllable per run without an env var.

Changes

  • Add a --timeout <duration> flag to start (and the bare root, which starts the emulator when invoked with no subcommand).
  • When set explicitly, the flag overrides the env/config-derived cfg.StartupTimeout for that run (applyTimeoutFlag in cmd/root.go). An unset flag preserves LSTK_STARTUP_TIMEOUT, which in turn falls back to the per-mode default in resolveStartupTimeout (20s interactive / 60s non-interactive).
  • --timeout 0 uses the per-mode default rather than disabling the timeout — there is intentionally no indefinite wait (that was the hang Fix lstk start waits forever when the container fails during startup #390 fixed). This differs from the flag behavior originally suggested on the ticket (5m default, 0 disables), which predates Fix lstk start waits forever when the container fails during startup #390's mechanism.
  • restart and the snapshot auto-start path deliberately do not expose the flag; they keep using the env/config value.
  • Document the flag on the LSTK_STARTUP_TIMEOUT entry in CLAUDE.md.

Scope note: the timeout mechanism itself — startupMonitor, per-mode defaults, the interactive keep-waiting/stop prompt, startupTimeoutError, and the start_timeout telemetry code — landed in #390. After rebasing onto main this PR is scoped to exposing that mechanism as a CLI flag plus a non-interactive integration test.

Review

Human review advised — adds new user-facing behavior (a --timeout flag), which the review-scope checklist routes to human review regardless of diff size.

Tests

  • New integration test TestStartTimesOutWhenEmulatorNeverBecomesHealthy: starts a local image that stays running but never serves /_localstack/health, runs start --timeout 3s non-interactively, and asserts the fast failure (clear error + exit 1).
  • Unit coverage of the mechanism (TestStartupMonitorAwait_*, TestResolveStartupTimeout, TestStartContainers_TimeoutEmitsErrorAndTelemetry) is retained from Fix lstk start waits forever when the container fails during startup #390.
  • Manual: go build ./...; lstk start --help and lstk --help both list --timeout; an invalid value (--timeout bogus) is rejected with a usage error.

Closes PRO-357

@gtsiolis gtsiolis self-assigned this Jul 2, 2026
@gtsiolis gtsiolis added semver: patch docs: needed Pull request requires documentation updates labels Jul 2, 2026
@gtsiolis
gtsiolis force-pushed the pro-357-lstk-start-should-time-out-on-failed-startup-0511 branch 4 times, most recently from 85218c6 to 6b23b5a Compare July 9, 2026 07:13
@gtsiolis
gtsiolis force-pushed the pro-357-lstk-start-should-time-out-on-failed-startup-0511 branch 2 times, most recently from f00d3ea to dd4f388 Compare July 16, 2026 07:09
lstk start (and the bare root) now accept --timeout <duration> to bound how long lstk waits for the emulator to report healthy. When set explicitly it overrides LSTK_STARTUP_TIMEOUT for a single run; --timeout 0 falls back to the per-mode default. restart and the snapshot auto-start path deliberately do not expose the flag.

The underlying startup-timeout mechanism — per-mode defaults, the interactive keep-waiting/stop prompt, and startupMonitor — landed separately in #390; this change only exposes it as a CLI flag and adds an integration test covering the non-interactive timeout path.

Generated with [Linear](https://linear.app/localstack/issue/PRO-357/lstk-start-should-time-out-on-failed-startup#agent-session-92655d31)

Co-authored-by: linear-code[bot] <222613912+linear-code[bot]@users.noreply.github.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@gtsiolis
gtsiolis force-pushed the pro-357-lstk-start-should-time-out-on-failed-startup-0511 branch from dd4f388 to 018812c Compare July 23, 2026 09:07
@gtsiolis gtsiolis changed the title feat: add --timeout to bound emulator startup wait feat: add --timeout flag to override the startup readiness deadline Jul 23, 2026
@gtsiolis
gtsiolis marked this pull request as ready for review July 23, 2026 09:13
@gtsiolis
gtsiolis requested a review from a team as a code owner July 23, 2026 09:13
gtsiolis and others added 2 commits July 23, 2026 12:28
… wait

Co-Authored-By: Claude <noreply@anthropic.com>

@skyrpex skyrpex left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not much to say, it looks good to me and the functionality is very welcomed.

@gtsiolis
gtsiolis merged commit 36f28d7 into main Jul 23, 2026
17 checks passed
@gtsiolis
gtsiolis deleted the pro-357-lstk-start-should-time-out-on-failed-startup-0511 branch July 23, 2026 11:02
@skyrpex

skyrpex commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

BTW love the difference in behavior between interactive and non-interactive.

Interactive:

$ ./bin/lstk start --timeout 1s

   ▟████▖   lstk (dev)
  ▟██▙█▙█▟  LocalStack Enterprise
    ▀▛▀▛▀   ~/.config/lstk/config.toml

✔︎ Pulled localstack/localstack-pro:latest
✔︎ Valid license (Enterprise)
? LocalStack is taking longer than expected to start. Check logs with 'lstk logs' [Keep waiting [W]/Stop LocalStack and exit [S]]

Non-interactive:

$ ./bin/lstk start --timeout 1s | cat
Pulling localstack/localstack-pro:latest...
Preparing LocalStack...
✔︎ Pulled localstack/localstack-pro:latest
Checking license...
✔︎ Valid license (Enterprise)
Starting LocalStack...
Error: LocalStack did not become ready within 1s
  LocalStack is still running so you can inspect it, or stop it.
Last container output:

LocalStack version: 2026.7.0
LocalStack build date: 2026-07-22
LocalStack build git hash: 983eb90ac

2026-07-23T11:03:12.601  INFO --- [  MainThread] l.licensing.licensingv2    : Successfully activated cached license 970b3ec2-1299-4ead-8597-84ab74a5d3f0:enterprise from /var/lib/localstack/cache/license.json 🔑✅
2026-07-23T11:03:13.290  INFO --- [  MainThread] localstack.utils.bootstrap : Execution of "_resolve_api_provider_specs" took 623.13ms
  ==> View the logs: lstk logs
  ==> Stop LocalStack: lstk stop
  ==> Allow more time on a slow machine: LSTK_STARTUP_TIMEOUT=5m lstk start

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs: needed Pull request requires documentation updates semver: minor

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants